{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import sys\n",
    "\n",
    "sys.path.append(r\"../../../\")\n",
    "from python_quant.stock.side.fundamentals_side.finance_side import finance_diag_newest_score\n",
    "from python_quant.stock.side.properbliy_side.rise_properbliy import dfcf_next_five_day_rise_properbliy_more_than, \\\n",
    "    dfcf_next_five_day_rise_properbliy_more_than_with_out_rose_rate\n",
    "from python_quant.stock.side.theme_side.theme_side import todayopportunity, eastmoney_recent_hot_theme\n",
    "from python_quant.stock.myTT import MA\n",
    "# path = \"C:\\mySpace\\DEVTEST\\stocks&future\\python_quant\"\n",
    "\n",
    "#sys.path.insert(0,\"..\")\n",
    "\n",
    "\n",
    "import akshare as ak\n",
    "import pandas as pd\n",
    "import datetime\n",
    "import MyTT\n",
    "\n",
    "#print(sys.path)\n",
    "from python_quant.common.code import code_to_sz_sh_symbol\n",
    "from python_quant.common.date import date_format\n",
    "from datetime import date\n",
    "from python_quant.common.constant import DATE_FORMAT_PARTTERN_YMD,DATE_FORMAT_PARTTERN_Y_M_D"
   ]
  },
  {
   "cell_type": "markdown",
   "source": [
    "\n",
    "因子维度\n",
    "同一纬度取并集，不同维度取交集\n",
    "A\n",
    "\n",
    "基本面\n",
    "-财务面\n",
    "--东方财富财务体检大于70分√\n",
    "\n",
    "估值面\n",
    "--百度股市通估值折半位√\n",
    "\n",
    "估价面\n",
    "--历史复权价折半位√\n",
    "\n",
    "资金面\n",
    "--东方财富超大资金、大资金、中单净流入√\n",
    "--东方财富涨停板行情10:30分之前涨停并且当日没开板的√\n",
    "\n",
    "人气面\n",
    "--东方财富股吧人气上升√\n",
    "\n",
    "题材面\n",
    "--东方财富主题投资√\n",
    "\n",
    "技术面\n",
    "\n",
    "概率统计面\n",
    "--东方财富次日上涨概率\n",
    "\n",
    "B\n",
    "市场\n",
    "行业\n",
    "概念\n",
    "个股"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "题材面\n",
    "--东方财富主题投资"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "outputs": [
    {
     "data": {
      "text/plain": "0       002229\n4       002717\n8       300136\n10      301236\n16      603466\n         ...  \n1947    002777\n1948    600730\n1949    301171\n1950    300130\n1951    301085\nName: 代码, Length: 1351, dtype: object"
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "today_stocks = todayopportunity()\n",
    "recent_stocks = eastmoney_recent_hot_theme()\n",
    "theme_stocks_df = pd.merge(today_stocks, recent_stocks, on=['代码'], how='outer').drop_duplicates('代码')\n",
    "theme_stocks = theme_stocks_df['代码']\n",
    "theme_stocks"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "资金面\n",
    "--东方财富超大资金、大资金、中单净流入"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "outputs": [
    {
     "data": {
      "text/plain": "0       688361\n6       301428\n12      688249\n13      002222\n26      300474\n         ...  \n1438    600543\n1470    603609\n1496    603199\n1523    600569\n1545    603048\nName: 代码, Length: 186, dtype: object"
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "amount_df = ak.stock_individual_fund_flow_rank(indicator=\"今日\")\n",
    "amount_clear_df = amount_df[\n",
    "        (amount_df['今日主力净流入-净占比'].str.contains('-') == True)\n",
    "        | (amount_df['今日超大单净流入-净占比'].str.contains('-') == True)\n",
    "        | (amount_df['今日大单净流入-净占比'].str.contains('-') == True)\n",
    "        | (amount_df['今日中单净流入-净占比'].str.contains('-') == True)\n",
    "        ]\n",
    "\n",
    "set_diff_df = pd.concat([amount_df, amount_clear_df, amount_clear_df]).drop_duplicates(keep=False)\n",
    "\n",
    "in_rate = 0\n",
    "\n",
    "set_diff_df = set_diff_df[\n",
    "        (set_diff_df['今日中单净流入-净占比'].astype('float') > in_rate) &\n",
    "(set_diff_df['今日大单净流入-净占比'].astype('float') > in_rate) &\n",
    "(set_diff_df['今日主力净流入-净占比'].astype('float') > in_rate) & (\n",
    "        set_diff_df['今日超大单净流入-净占比'].astype('float') > in_rate)]\n",
    "\n",
    "amount_in_codes = set_diff_df['代码']\n",
    "amount_in_codes"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "-10点半之前的涨停板并且没有开板"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "outputs": [
    {
     "data": {
      "text/plain": "0     002689\n6     301368\n8     002213\n9     002406\n10    603933\n12    002217\n14    600182\nName: 代码, dtype: object"
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "today = date.today()\n",
    "trade_date_df = ak.tool_trade_date_hist_sina()\n",
    "trade_date_list = trade_date_df[\"trade_date\"].astype(str).tolist()\n",
    "while str(today) not in trade_date_list:  # 如果当前日期不在交易日期列表内，则当前日期天数减一\n",
    "    today = today - datetime.timedelta(days=1)\n",
    "today = date_format(str(today),DATE_FORMAT_PARTTERN_Y_M_D,DATE_FORMAT_PARTTERN_YMD)\n",
    "stock_zt_pool_em_df = ak.stock_zt_pool_em(date=today)\n",
    "stock_zt_pool_em_df = stock_zt_pool_em_df[\n",
    "    (stock_zt_pool_em_df['首次封板时间'] <= '103000') & (stock_zt_pool_em_df['最后封板时间'] <= '103000') & (\n",
    "            stock_zt_pool_em_df['炸板次数'] == 0)]\n",
    "stock_zt_pool_codes = stock_zt_pool_em_df['代码']\n",
    "stock_zt_pool_codes"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "资金面取并集"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "outputs": [
    {
     "data": {
      "text/plain": "         代码\n0    002689\n1    301368\n2    002213\n3    002406\n4    603933\n..      ...\n188  600543\n189  603609\n190  603199\n191  600569\n192  603048\n\n[193 rows x 1 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>代码</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>002689</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>301368</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>002213</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>002406</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>603933</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>188</th>\n      <td>600543</td>\n    </tr>\n    <tr>\n      <th>189</th>\n      <td>603609</td>\n    </tr>\n    <tr>\n      <th>190</th>\n      <td>603199</td>\n    </tr>\n    <tr>\n      <th>191</th>\n      <td>600569</td>\n    </tr>\n    <tr>\n      <th>192</th>\n      <td>603048</td>\n    </tr>\n  </tbody>\n</table>\n<p>193 rows × 1 columns</p>\n</div>"
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "amount_in_codes = pd.merge(stock_zt_pool_codes,amount_in_codes,on='代码', how='outer')\n",
    "amount_in_codes"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "题材面+资金面"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "outputs": [
    {
     "data": {
      "text/plain": "        代码\n0   002213\n1   603933\n2   002217\n3   301428\n4   300474\n5   600690\n6   300033\n7   300394\n8   603290\n9   600895\n10  600460\n11  300250\n12  300101\n13  300566\n14  600406\n15  600183\n16  601133\n17  603160\n18  603068\n19  002786\n20  300708\n21  000016\n22  002402\n23  000636\n24  300037\n25  601231\n26  600360\n27  603078\n28  300395\n29  000913\n30  300323\n31  300217\n32  300619\n33  300398\n34  603869\n35  600860\n36  300706\n37  301086\n38  600067\n39  603717\n40  002418\n41  000828\n42  300353\n43  600173\n44  600378\n45  300286\n46  002644\n47  002149\n48  601512",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>代码</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>002213</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>603933</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>002217</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>301428</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>300474</td>\n    </tr>\n    <tr>\n      <th>5</th>\n      <td>600690</td>\n    </tr>\n    <tr>\n      <th>6</th>\n      <td>300033</td>\n    </tr>\n    <tr>\n      <th>7</th>\n      <td>300394</td>\n    </tr>\n    <tr>\n      <th>8</th>\n      <td>603290</td>\n    </tr>\n    <tr>\n      <th>9</th>\n      <td>600895</td>\n    </tr>\n    <tr>\n      <th>10</th>\n      <td>600460</td>\n    </tr>\n    <tr>\n      <th>11</th>\n      <td>300250</td>\n    </tr>\n    <tr>\n      <th>12</th>\n      <td>300101</td>\n    </tr>\n    <tr>\n      <th>13</th>\n      <td>300566</td>\n    </tr>\n    <tr>\n      <th>14</th>\n      <td>600406</td>\n    </tr>\n    <tr>\n      <th>15</th>\n      <td>600183</td>\n    </tr>\n    <tr>\n      <th>16</th>\n      <td>601133</td>\n    </tr>\n    <tr>\n      <th>17</th>\n      <td>603160</td>\n    </tr>\n    <tr>\n      <th>18</th>\n      <td>603068</td>\n    </tr>\n    <tr>\n      <th>19</th>\n      <td>002786</td>\n    </tr>\n    <tr>\n      <th>20</th>\n      <td>300708</td>\n    </tr>\n    <tr>\n      <th>21</th>\n      <td>000016</td>\n    </tr>\n    <tr>\n      <th>22</th>\n      <td>002402</td>\n    </tr>\n    <tr>\n      <th>23</th>\n      <td>000636</td>\n    </tr>\n    <tr>\n      <th>24</th>\n      <td>300037</td>\n    </tr>\n    <tr>\n      <th>25</th>\n      <td>601231</td>\n    </tr>\n    <tr>\n      <th>26</th>\n      <td>600360</td>\n    </tr>\n    <tr>\n      <th>27</th>\n      <td>603078</td>\n    </tr>\n    <tr>\n      <th>28</th>\n      <td>300395</td>\n    </tr>\n    <tr>\n      <th>29</th>\n      <td>000913</td>\n    </tr>\n    <tr>\n      <th>30</th>\n      <td>300323</td>\n    </tr>\n    <tr>\n      <th>31</th>\n      <td>300217</td>\n    </tr>\n    <tr>\n      <th>32</th>\n      <td>300619</td>\n    </tr>\n    <tr>\n      <th>33</th>\n      <td>300398</td>\n    </tr>\n    <tr>\n      <th>34</th>\n      <td>603869</td>\n    </tr>\n    <tr>\n      <th>35</th>\n      <td>600860</td>\n    </tr>\n    <tr>\n      <th>36</th>\n      <td>300706</td>\n    </tr>\n    <tr>\n      <th>37</th>\n      <td>301086</td>\n    </tr>\n    <tr>\n      <th>38</th>\n      <td>600067</td>\n    </tr>\n    <tr>\n      <th>39</th>\n      <td>603717</td>\n    </tr>\n    <tr>\n      <th>40</th>\n      <td>002418</td>\n    </tr>\n    <tr>\n      <th>41</th>\n      <td>000828</td>\n    </tr>\n    <tr>\n      <th>42</th>\n      <td>300353</td>\n    </tr>\n    <tr>\n      <th>43</th>\n      <td>600173</td>\n    </tr>\n    <tr>\n      <th>44</th>\n      <td>600378</td>\n    </tr>\n    <tr>\n      <th>45</th>\n      <td>300286</td>\n    </tr>\n    <tr>\n      <th>46</th>\n      <td>002644</td>\n    </tr>\n    <tr>\n      <th>47</th>\n      <td>002149</td>\n    </tr>\n    <tr>\n      <th>48</th>\n      <td>601512</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "codes = pd.merge(amount_in_codes,theme_stocks,how='inner', on=['代码']).drop_duplicates()\n",
    "codes"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "基本面\n",
    "-财务面\n",
    "--东方财富财务体检大于70分"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "score = finance_diag_newest_score('000606')\n",
    "score"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "资金面+财务面+题材面"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "outputs": [
    {
     "data": {
      "text/plain": "['300474',\n '600690',\n '300033',\n '300394',\n '603290',\n '600183',\n '603160',\n '002402',\n '000636',\n '300037',\n '601231',\n '300395',\n '300217',\n '300619',\n '301086',\n '600067',\n '000828',\n '600173',\n '300286']"
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "code_fin_list = list()\n",
    "for code in codes['代码'].values:\n",
    "       score = finance_diag_newest_score(code)\n",
    "       if score is not None and score>=70:\n",
    "            code_fin_list.append(code)\n",
    "code_fin_list"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "资金面+财务面+题材面+人气"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "300474 44\n",
      "600690 523\n",
      "603290 571\n",
      "603160 568\n",
      "002402 560\n",
      "000636 588\n",
      "300037 283\n",
      "601231 1184\n",
      "300395 1447\n",
      "600067 199\n",
      "600173 165\n",
      "300286 1409\n"
     ]
    }
   ],
   "source": [
    "rank_list = list()\n",
    "for code in code_fin_list:\n",
    "    full_code = code_to_sz_sh_symbol(code)\n",
    "    stock_hot_rank_detail_em_df = ak.stock_hot_rank_detail_em(symbol=full_code)\n",
    "    ranks = stock_hot_rank_detail_em_df['排名'].values\n",
    "    rank_div = ranks[-2]-ranks[-1]\n",
    "    if rank_div>0:\n",
    "        print(code, rank_div)\n",
    "        rank_list.append(str(code))\n"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "估价面"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "now_date = datetime.datetime.now().strftime('%Y%m%d')\n",
    "stock_zh_a_hist_df = ak.stock_zh_a_hist(symbol=\"000606\", period=\"daily\", start_date=\"19910101\", end_date=now_date, adjust=\"qfq\")\n",
    "closes = stock_zh_a_hist_df['收盘'].values\n",
    "mas = ta.MA(closes,len(closes))\n",
    "ma_all = mas[-1]\n",
    "mid_high = max(closes)/2"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "资金面+财务面+题材面+人气+估价"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "outputs": [
    {
     "data": {
      "text/plain": "['603160']"
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "code_to_list = list()\n",
    "for code in rank_list:\n",
    "    now_date = datetime.datetime.now().strftime('%Y%m%d')\n",
    "    stock_zh_a_hist_df = ak.stock_zh_a_hist(symbol=code, period=\"daily\", start_date=\"19910101\", end_date=now_date, adjust=\"qfq\")\n",
    "    closes = stock_zh_a_hist_df['收盘'].values\n",
    "    mas = MA(closes,len(closes))\n",
    "    ma_all = mas[-1]\n",
    "    mid_high = max(closes)/2\n",
    "    min_price = min(ma_all,mid_high)\n",
    "    if closes[-1]<min_price and (closes[-1]-min_price)/min_price*100<-20:\n",
    "        code_to_list.append(code)\n",
    "\n",
    "code_to_list"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "估值"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "市净率"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "list indices must be integers or slices, not str",
     "output_type": "error",
     "traceback": [
      "\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[1;31mTypeError\u001B[0m                                 Traceback (most recent call last)",
      "Cell \u001B[1;32mIn[10], line 1\u001B[0m\n\u001B[1;32m----> 1\u001B[0m stock_zh_valuation_baidu_df \u001B[38;5;241m=\u001B[39m \u001B[43mak\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mstock_zh_valuation_baidu\u001B[49m\u001B[43m(\u001B[49m\u001B[43msymbol\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[38;5;124;43m\"\u001B[39;49m\u001B[38;5;124;43m002044\u001B[39;49m\u001B[38;5;124;43m\"\u001B[39;49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mindicator\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[38;5;124;43m\"\u001B[39;49m\u001B[38;5;124;43m市净率\u001B[39;49m\u001B[38;5;124;43m\"\u001B[39;49m\u001B[43m)\u001B[49m\n\u001B[0;32m      2\u001B[0m values \u001B[38;5;241m=\u001B[39m stock_zh_valuation_baidu_df[\u001B[38;5;124m'\u001B[39m\u001B[38;5;124mvalue\u001B[39m\u001B[38;5;124m'\u001B[39m]\u001B[38;5;241m.\u001B[39mvalues\n\u001B[0;32m      3\u001B[0m ma_values \u001B[38;5;241m=\u001B[39m MyTT\u001B[38;5;241m.\u001B[39mMA(values,\u001B[38;5;28mlen\u001B[39m(values))\n",
      "File \u001B[1;32mC:\\mySpace\\mysoftware\\anaconda\\envs\\jue_jin\\lib\\site-packages\\akshare\\stock_feature\\stock_zh_valuation_baidu.py:43\u001B[0m, in \u001B[0;36mstock_zh_valuation_baidu\u001B[1;34m(symbol, indicator, period)\u001B[0m\n\u001B[0;32m     41\u001B[0m r \u001B[38;5;241m=\u001B[39m conn\u001B[38;5;241m.\u001B[39mgetresponse()\n\u001B[0;32m     42\u001B[0m data_json \u001B[38;5;241m=\u001B[39m json\u001B[38;5;241m.\u001B[39mloads(r\u001B[38;5;241m.\u001B[39mread())\n\u001B[1;32m---> 43\u001B[0m temp_df \u001B[38;5;241m=\u001B[39m pd\u001B[38;5;241m.\u001B[39mDataFrame(\u001B[43mdata_json\u001B[49m\u001B[43m[\u001B[49m\u001B[38;5;124;43m\"\u001B[39;49m\u001B[38;5;124;43mResult\u001B[39;49m\u001B[38;5;124;43m\"\u001B[39;49m\u001B[43m]\u001B[49m\u001B[43m[\u001B[49m\u001B[38;5;124;43m\"\u001B[39;49m\u001B[38;5;124;43mchartInfo\u001B[39;49m\u001B[38;5;124;43m\"\u001B[39;49m\u001B[43m]\u001B[49m[\u001B[38;5;241m0\u001B[39m][\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mbody\u001B[39m\u001B[38;5;124m\"\u001B[39m])\n\u001B[0;32m     44\u001B[0m temp_df\u001B[38;5;241m.\u001B[39mcolumns \u001B[38;5;241m=\u001B[39m [\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mdate\u001B[39m\u001B[38;5;124m\"\u001B[39m, \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mvalue\u001B[39m\u001B[38;5;124m\"\u001B[39m]\n\u001B[0;32m     45\u001B[0m temp_df[\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mdate\u001B[39m\u001B[38;5;124m\"\u001B[39m] \u001B[38;5;241m=\u001B[39m pd\u001B[38;5;241m.\u001B[39mto_datetime(temp_df[\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mdate\u001B[39m\u001B[38;5;124m\"\u001B[39m])\u001B[38;5;241m.\u001B[39mdt\u001B[38;5;241m.\u001B[39mdate\n",
      "\u001B[1;31mTypeError\u001B[0m: list indices must be integers or slices, not str"
     ]
    }
   ],
   "source": [
    "stock_zh_valuation_baidu_df = ak.stock_zh_valuation_baidu(symbol=\"002044\", indicator=\"市净率\")\n",
    "values = stock_zh_valuation_baidu_df['value'].values\n",
    "ma_values = MyTT.MA(values,len(values))\n",
    "mid_high_value = max(values)/2\n",
    "min_value = min(mid_high_value,ma_values[-1])\n",
    "percent = (values[-1]-min_value)/min_value*100\n",
    "percent"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "市现率"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "stock_zh_valuation_baidu_df = ak.stock_zh_valuation_baidu(symbol=\"002044\", indicator=\"市现率\")\n",
    "values = stock_zh_valuation_baidu_df['value'].values\n",
    "ma_values = MyTT.MA(values,len(values))\n",
    "mid_high_value = max(values)/2\n",
    "min_value = min(mid_high_value,ma_values[-1])\n",
    "percent = (values[-1]-min_value)/min_value*100\n",
    "percent"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "TTM市盈率"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "stock_zh_valuation_baidu_df = ak.stock_zh_valuation_baidu(symbol=\"002044\", indicator=\"市盈率(TTM)\")\n",
    "values = stock_zh_valuation_baidu_df['value'].values\n",
    "ma_values = MyTT.MA(values,len(values))\n",
    "mid_high_value = max(values)/2\n",
    "min_value = min(mid_high_value,ma_values[-1])\n",
    "percent = (values[-1]-min_value)/min_value*100\n",
    "percent"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "资金面+财务面+题材面+估价+估值\n",
    "财务大于70分+题材事件+资金流入+低估价+低估值"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "def get_value_percent(stock_zh_valuation_baidu_df):\n",
    "    values = stock_zh_valuation_baidu_df['value'].values\n",
    "    ma_values = MyTT.MA(values,len(values))\n",
    "    mid_high_value = max(values)/2\n",
    "    min_value = min(mid_high_value,ma_values[-1])\n",
    "    percent = (values[-1]-min_value)/min_value*100\n",
    "    return percent\n",
    "\n",
    "percent_list = list()\n",
    "\n",
    "for code in code_to_list:\n",
    "    pb_df = ak.stock_zh_valuation_baidu(symbol=code, indicator=\"市净率\")\n",
    "    pb_percent = get_value_percent(pb_df)\n",
    "    pe_df = ak.stock_zh_valuation_baidu(symbol=code, indicator=\"市盈率(TTM)\")\n",
    "    pe_percent = get_value_percent(pe_df)\n",
    "    ps_df = ak.stock_zh_valuation_baidu(symbol=code, indicator=\"市现率\")\n",
    "    ps_percent = get_value_percent(ps_df)\n",
    "    # 故意调整为pb和pe\n",
    "    if pb_percent<0 and pe_percent<0 and ps_percent<0:\n",
    "        percent_list.append(code)\n",
    "percent_list"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "人气面\n",
    "东方财富股吧热度"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "stock_hot_rank_detail_em_df = ak.stock_hot_rank_detail_em(symbol=\"sz300782\")\n",
    "stock_hot_rank_detail_em_df"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "资金面+财务面+题材面+估价+估值+人气+未来5日上涨概率大于50%"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "32.9166666666667\n",
      "603160 False\n"
     ]
    }
   ],
   "source": [
    "for code in code_to_list:\n",
    "    proper = dfcf_next_five_day_rise_properbliy_more_than_with_out_rose_rate(str(code),50)\n",
    "    print(code, proper)"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "分析\n",
    "在晚上6点之后运行程序\n",
    "\n",
    "选出来的票进行二次分析\n",
    "佣金宝相似k线六维分析，相对于自身历史和全市场相似度都大于70%的观察未来走势，设定目标止盈位\n",
    "同花顺相似k线\n",
    "东方财富相似k线\n",
    "\n",
    "使用mootdx分析区间高低价的成交金额最大的价格，价格要在当前价格上方至少有20%的空间\n",
    "\n",
    "买入\n",
    "选出票后第二天买入\n",
    "\n",
    "仓位-建仓\n",
    "10000\n",
    "\n",
    "加仓-条件\n",
    "相对于初始建仓价格下跌10%\n",
    "RSI极限点或者通达信全部资金净买入\n",
    "\n",
    "加仓-金额\n",
    "上次建仓或者加仓的2倍\n",
    "\n",
    "卖出-止盈\n",
    "盈利20%\n",
    "全部资金净卖出\n",
    "盈利情况下有新的符合标准的标的\n",
    "价格达到区间高低价的成交金额最大的价格时\n"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [],
   "metadata": {
    "collapsed": false
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
